package bairui.international.console.web.controller.finance.order;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.project.commons.util.Util_FileDeal;
import com.lianjing.sh.project.commons.util.Util_FileDeal.FileInfo;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_ProductOrder;
import bairui.international.service.Service_ProductOrder;

/**
 *
 * 详情
 *
 * @generated
 * 
 * @see STest_C_Finance_ProductOrder_Detail_Edit 测试
 *
 */
@Controller
public class C_Finance_ProductOrder_Detail_Edit
 extends SC_Finance_ProductOrder_Detail_Edit 
{
	
	@Autowired private Service_ProductOrder service_ProductOrder;
	
	/**
	 * 编辑
	 */
	@Action(Edit.class)
	@PostMapping(Edit.RequestMappingValue)
	public @FomatOutput @ResponseBody Object edit(
		@Valid Edit.InputModel input, 
		@PathVariable(name=Edit.PathVariableName.Id) long id
	) throws Exception {
		String remitImgUrl = service_ProductOrder.findById(id).getRemitImgUrl();
		if(null == remitImgUrl){	// 添加
			// 保存图片相关
			FileInfo fileInfo = Util_FileDeal.saveFile(input.getRemitImgUrlFile(), pathConfig.getPosition_Image_Order_RemitImg());
			// 保存数据
			service_ProductOrder.setRemitImgUrl(id, fileInfo.getName());
		}else{	// 更新
			// 更新数据
			TB_ProductOrder bean = service_ProductOrder.updateWithNonNullProperties(id, input);
			// 更新图片
			Util_FileDeal.updateFile(input.gainRemitImgUrlFile(), bean.getRemitImgUrl(), pathConfig.getPosition_Image_Order_RemitImg());
		}
		//
		return null;
	}
	

}
